package com.sunwayworld.basemodule.basedata.zksample.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.sunwayworld.framework.spring.annotation.GikamBean;

import com.sunwayworld.basemodule.basedata.zksample.dao.LimsZkSampleTemplateDao;
import com.sunwayworld.basemodule.basedata.zksample.bean.LimsZkSampleTemplateBean;
import com.sunwayworld.basemodule.basedata.zksample.service.LimsZkSampleTemplateService;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;

import java.util.List;

@Repository
@GikamBean
public class LimsZkSampleTemplateServiceImpl implements LimsZkSampleTemplateService {

    @Autowired
    private LimsZkSampleTemplateDao limsZkSampleTemplateDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsZkSampleTemplateDao getDao() {
        return limsZkSampleTemplateDao;
    }

    @Override
    @Transactional
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsZkSampleTemplateBean limsZkSampleTemplate = jsonWrapper.parseUnique(LimsZkSampleTemplateBean.class);
        limsZkSampleTemplate.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsZkSampleTemplate);
        return limsZkSampleTemplate.getId();
    }

    @Override
    @Transactional
    public void delete(RestJsonWrapperBean wrapper) {
        List<Long> zkSampleTemplateIds = wrapper.parseId(Long.class);
        getDao().deleteByIdList(zkSampleTemplateIds);
    }
}
